import { GETPMMLLIST, GETMODELVERSIONS } from '../action_types'
import AxiosUtils from '../../../commons/axios'

/**
 * pmml模块列表展示逻辑
 * @param {*} page 分页，当前页码
 * @param {*} search 搜索关键字
 * @returns 模型列表
 */
export const getPmmlList = (page, search) => {
    return dispatch => {
        let url = "/model/list"
        AxiosUtils.ajax({
            url: url,
            data: {
                params: {
                    page: page,
                    search: search
                },
                isShowLoading: true
            },
            method: 'get'
        }).then(res => {
            if(res.code === 0) {
                dispatch(pmmlAction(res.data))
            }
        })
    }
}

const pmmlAction = rawData => ({
    type: GETPMMLLIST,
    data: rawData
})

/**
 * 获取模型对应的多个版本的文件
 * @param {*} id 模型ID
 * @returns 模型对应的版本文件列表
 */
export const getModelVersions = id => {
    return dispatch => {
        let url = "/model/versions/" + id
        AxiosUtils.ajax({
            url: url,
            method: 'get'
        }).then(res => {
            if(res.code === 0) {
                dispatch(versionAction(res.data))
            }
        })
    }
}

const versionAction = rawData => ({
    type: GETMODELVERSIONS,
    data: rawData
})